class Solution {
    public long largestPerimeter(int[] nums) {
        Arrays.sort(nums);
        long  ans = -1,tmp = 0;
        for(int x:nums){
            tmp += x;
            if(tmp - x > x)
                ans = tmp;
        }return ans;
    }
}